﻿using Autodesk.Revit.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using xyz = Autodesk.Revit.DB.XYZ;
namespace RevitAddin
{
    public class RevitCurve
    {
        public class RevitFilter
        {
            /// <summary>
            /// 在指定文档中查找指定类型的元素
            /// </summary>
            /// <param name="doc"></param>
            /// <param name="type"></param>
            /// <returns></returns>
            public static List<Element> FilterEle(Document doc, Type type)
            {
                FilteredElementCollector collector = new FilteredElementCollector(doc);
                return collector.OfClass(type).ToElements().ToList().ConvertAll(e => e as Element);
            }
            /// <summary>   
            /// 查找指定参数
            /// </summary>
            /// <param name="paraName"></param>
            /// <param name="ele"></param>
            /// <returns></returns>
            public static Parameter FindParameter(string paraName, Element ele)
            {
                ParameterSet parameters = ele.Parameters;
                foreach (Parameter parameter in parameters)
                {
                    string paramName = parameter.Definition.Name;
                    // 判断参数名称是否符合条件
                    if (paramName == paraName)
                    {
                        return parameter;
                    }
                }
                return null;
            }
        }
        /// <summary>
        /// 绘制球体
        /// </summary>
        /// <param name="point"></param>
        /// <param name="doc"></param>
        public static FamilyInstance drawFamilyInstance(xyz point, Document doc, string familyName)
        {
            List<Element> symbols = RevitFilter.FilterEle(doc, typeof(FamilySymbol));
            FamilySymbol symble = null;
            foreach (FamilySymbol ele in symbols)
            {
                if (ele.Name.Equals(familyName))
                {
                    symble = ele;
                    break;
                }
            }
            symble.Activate();
            FamilyInstance familyInstance = doc.Create.NewFamilyInstance(point, symble, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);

            return familyInstance;
        }
    }
}
